package east;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import robocode.AdvancedRobot;
import robocode.DeathEvent;
import robocode.RobotDeathEvent;
import robocode.ScannedRobotEvent;
import robocode.WinEvent;
import robocode.util.Utils;

public class CircleMover
{
	private AdvancedRobot r;
	private double radius = 115;
 	private double center[];
 	private double x;
 	private double y;
 	private double pos;
	private double desiredheading;
	private double currentheading;
	public boolean inorbit = false;
	public boolean inalignedorbit = false;
	public boolean leftside;
		
	public CircleMover(AdvancedRobot robot) {
		this.r = robot;	
		center = new double [2];
		center[0] = r.getBattleFieldWidth()/2; 
 		center[1] = r.getBattleFieldHeight()/2;

	}
	
	public void alignOrbit() {
		desiredheading = - Math.atan2(y, x);
		currentheading = r.getHeading() * Math.PI / 180 - Math.PI;
		while (Math.abs(currentheading - desiredheading) > .1) {
			r.setTurnRightRadians(desiredheading - currentheading);
			currentheading = r.getHeading() * Math.PI / 180 - Math.PI;
			r.execute();
		}
		inalignedorbit = true;
    	System.out.print("in aligned orbit!");
	}
	
public void findOrbit(double speed) {
	x = r.getX() - center[0];
    y = r.getY() - center[1];
    currentheading = r.getHeading();
    desiredheading = Math.atan2(x, y) * 180 / Math.PI + 180;
    if (desiredheading < 0) {
    	desiredheading = 0;
    }
	r.setTurnRight(desiredheading - currentheading);
	r.setAhead(speed);
    r.execute();
    pos = Math.sqrt(Math.pow(x,2) + Math.pow(y,2));

    if (pos < radius*2){
    	inorbit = true;
    	System.out.print("in orbit!");
    	r.setAhead(0);
    	if (x < 0) {
    		leftside = true;
    	}
    }
}

	public void move(double speed) {
		System.out.print("hi!");
		r.setAhead(speed);
		System.out.print(r.getVelocity()/radius);
		r.setTurnRightRadians(r.getVelocity()/radius);
		r.execute();
	}

}
